/**
  *@File文件:ImpShoppingCartService.java
  *@Date日期:2017年7月18日 上午8:58:28
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.serviceImp;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qiaomengapp.bean.ShoppingCart;
import com.qiaomengapp.bean.GoodDetail;
import com.qiaomengapp.dao.ShoppingCartMapper;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.IShoppingCartService;

/**
 * @Description描述:
 * @Author作者 wangzongwen
 * @Date日期:2017年7月18日
 */
@Service
public class ImpShoppingCartService implements IShoppingCartService {

	@Autowired
	private ShoppingCartMapper shoppingCartMapper;

	@Override
	public void insertShoppingCart(ShoppingCart shoppingCart) throws CustomException {
		// 添加一条购物车信息
		int i = shoppingCartMapper.insertShoppingCart(shoppingCart);
		if (i == 0) {
			throw new CustomException("添加购物车失败");
		}
	}

	@Override
	public List<GoodDetail> selectShoppingCartGood(int userId, Integer[] shopGoodIds) {
		// 查询购物车商品信息
		List<GoodDetail> list;
		if (shopGoodIds == null) {
			list = shoppingCartMapper.selectShoppingCartGood(userId, null);
		} else {
			list = shoppingCartMapper.selectShoppingCartGood(userId, Arrays.asList(shopGoodIds));
		}
		return list;
	}

}
